
#include <mian_util.h>
#include "dict_compression.h"



template<class DataType>
void test_compression(const int maxValue) {
	const int numElement = 1024*1024;
	printf("numElement = %d, sizeof(DataType) = %d, maxValue = %d\n", 
		numElement, sizeof(DataType), maxValue);

	DataType* data = (DataType*)malloc(sizeof(DataType)*numElement);
	for(int i = 0; i < numElement; i++) {
		data[i] = rand()%maxValue;
	}
	DataType* gold_data = (DataType*)malloc(sizeof(DataType)*numElement);
	memcpy(gold_data, data, sizeof(DataType)*numElement);
	uint64 numWordCData = numElement;
	word* cData = (word*)malloc(sizeof(word)*numWordCData);
	uint64 numElementDict = numElement;
	DataType* dict = (DataType*)malloc(sizeof(DataType)*numElementDict);
	

	dictComprStart(numElement, sizeof(DataType));

	//compression
	cuda_dictCompression(cData, &numWordCData, dict, &numElementDict, data, numElement);


	//decompression
	DataType* dData = (DataType*)malloc(sizeof(DataType)*numElement);
	dictDecompression(dData, numElement, cData, numWordCData, dict, numElementDict);

	//check result
	simpleCheck(gold_data, dData, numElement);

	dictComprEnd();
	free(data);
	free(gold_data);
	free(cData);
	free(dData);
}


int main() {


	test_compression<int>(10000);
	printLine();

	test_compression<char>(100);

	return EXIT_SUCCESS;
}


